#include <iostream>

// 装饰器模式 增加现有类的功能
// 添加功能可以通过添加子类来完成 但是容易导致引入过多的子类
// 另一种方法便是 通过一个装饰器类 来实现添加更多功能
// 每增加一个功能 就可以增加一个装饰器类 可以对这些装饰器类进行装饰
// 以实现多个功能的组合

class Car {
public:
    virtual void show() = 0;
    virtual ~Car() {
    }
};

class Audi : public Car {
public:
    void show() override {
        std::cout << "This is a Audi car.";
    }
};

class Byd : public Car {
public:
    void show() override {
        std::cout << "This is a Byd car.";
    }
};

class BlueDecorator : public Car {
public:
    BlueDecorator(Car* car) : _car(car) {
    }
    void show() override {
        _car->show();
        blue();
    }

private:
    void blue() {
        std::cout << "It's blue.";
    }

private:
    Car* _car;
};

class BigDecorator : public Car {
public:
    BigDecorator(Car* car) : _car(car) {
    }

    void show() override {
        _car->show();
        big();
    }

private:
    void big() {
        std::cout << "It's big.";
    }
    Car* _car;
};

int main() {
    Car* byd = new Byd;
    Car* audi = new Audi;

    Car* blueByd = new BlueDecorator(byd);
    Car* bigAudi = new BigDecorator(audi);

    Car* bigBlueByd = new BigDecorator(blueByd);

    byd->show();
    std::cout << std::endl;
    audi->show();
    std::cout << std::endl;
    blueByd->show();
    std::cout << std::endl;
    bigAudi->show();
    std::cout << std::endl;
    bigBlueByd->show();
    std::cout << std::endl;

    delete bigBlueByd;
    delete bigAudi;
    delete blueByd;
    delete audi;
    delete byd;
}
